#include "querypackage.h"
#include "user.h"
#include <qjsondocument.h>
QJsonObject QueryPackage::toJson()const{
        QJsonObject json;
        json["userid"] = userid;
        return json;
}
QJsonObject OneWayQuery::toJson()const{
        QJsonObject json = QueryPackage::toJson();
        json["destination"] = dst;
        json["source"] = src;
        json["passengertype"] = User::RoleToString(r_psg);
        QJsonArray arr;
        for(const Vehicle& f:t_train){
            arr.append(QueryPackage::VehicleToString(f));
        }
        json["traintype"] = QString(QJsonDocument(arr).toJson(QJsonDocument::Compact));
        json["startdate"] = start.toString("yyyy-MM-dd");
        return json;
}
QJsonObject RoundTripQuery::toJson()const{
    QJsonObject json = QueryPackage::toJson();
    json["destination"] = dst;
    json["source"] = src;
    json["passengertype"] = User::RoleToString(r_psg);
    QJsonArray arr;
    for(const Vehicle& f:t_train){
        arr.append(VehicleToString(f));
    }
    json["traintype"] = QString(QJsonDocument(arr).toJson(QJsonDocument::Compact));
    json["startdate"] = start.toString("yyyy-MM-dd");
    json["enddate"] = end.toString("yyyy-MM-dd");
    return json;
}
QJsonObject TranferQuery::toJson()const{
    QJsonObject json = QueryPackage::toJson();
    json["destination"] = dst;
    json["source"] = src;
    json["passengertype"] = User::RoleToString(r_psg);
    QJsonArray arr;
    for(const Vehicle& f:t_train){
        arr.append(VehicleToString(f));
    }
    json["traintype"] = QString(QJsonDocument(arr).toJson(QJsonDocument::Compact));
    json["startdate"] = start.toString("yyyy-MM-dd");
    return json;
}
QJsonObject RefundQuery::toJson()const{
    QJsonObject json = QueryPackage::toJson();
    json["refundtype"] = refundtype;
    json["keyword"] = keyword;
    json["startdate"] = start.toString("yyyy-MM-dd");
    json["enddate"] = end.toString("yyyy-MM-dd");
    json["keywordtype"] = keywordtype;
    return json;
}
QJsonObject OnTimeQuery::toJson()const{
        QJsonObject json = QueryPackage::toJson();
        json["station"] = station;
        //json["isarrive"] = isArrive;
        json["trainid"] = trainid;
        return json;
}
QJsonObject OnSaleQuery::toJson()const{
    QJsonObject json = QueryPackage::toJson();
    json["startdate"] = start.toString();
    json["station"] = station;
    return json;
}
QJsonObject CheckPointQuery::toJson()const{
    QJsonObject json = QueryPackage::toJson();
    json["station"] = station;
    json["startdate"] = start.toString();
    json["trainid"] = train_id;
    return json;
}
